{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "view-in-github"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/jermwatt/machine_learning_refined/blob/main/notes/10_Nonlinear_intro/10_1_Intro.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "-bWMjrw41EbA"
   },
   "source": [
    "## Chapter 10: Nonlinear Learning and Feature Engineering"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook contains interactive content from an early draft of the university textbook <a href=\"https://github.com/neonwatty/machine-learning-refined/tree/main\">\n",
    "Machine Learning Refined (2nd edition) </a>.\n",
    "\n",
    "The final draft significantly expands on this content and is available for <a href=\"https://github.com/neonwatty/machine-learning-refined/tree/main/chapter_pdfs\"> download as a PDF here</a>."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hyjkua2K1EbB"
   },
   "source": [
    "# 10.1 Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Llb-MF8i1EbC"
   },
   "source": [
    "## 10.1.1 Mathematical, algorithmic, and empirical functions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "9VFmneZ91EbC"
   },
   "source": [
    "Throughout this text we have often used the word *function* to refer to mathematical formulae like that of a line, a quadratic, a logistic sigmoid, etc. Such formulae are often called *mathematical functions* as well, hence our use of the phrase 'function' to refer to them.  However the word 'function' is a much more general term, and broadly encompasses any rule or set of rules for assigning or transforming some kind of 'input' into some kind of 'output'.  For example a recipe for chocolate cake is an example of a function, that is a set of rules for how to take certain inputs - like eggs, flour, sugar, cocoa powder, etc., - and transform them into an 'output' chocolate cake.   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "SX7AC3751EbC"
   },
   "source": [
    "Another very common type of function is an *algorithm*, or one that is naturally expressed programaticaly (that is, in code).  A classic example of an *algorithmic function* is a basic *sorting scheme*.  Sorting schemes take in *input*  lists of numbers like the following\n",
    "\n",
    "\\begin{equation}\n",
    "[18,25,10,33,16,75,50,14]\n",
    "\\end{equation}\n",
    "\n",
    "and return as *output* its sorted version \n",
    "\n",
    "\\begin{equation}\n",
    "[10, 14, 16, 18, 25, 33, 50, 75].\n",
    "\\end{equation}\n",
    "\n",
    "Such a function is easy to express as code, and not so much in mathematical formulae."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0tkav3b81EbC"
   },
   "source": [
    "We have also seen a variety of algorithmic functions in prior Chapters.  For example *gradient descent* which (see Section 3.5) is an algorithmic function that takes in various inputs - a mathematical function to minimize, an initial point, a steplength, and a maximum number of steps to take - and returns certain outputs (e.g., a history of descent steps).  The process of building a Bag of Words histogram - as detailed at a high level in Section 9.1 - is another an example of an algorithmic function.  Here the input, raw text, is transformed into a numerical histogram representing counts of the words the input contains.  Such a function is much more easily detailed programatically, in code, than it is mathematically, using formulae. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GZIZPleE1EbD"
   },
   "source": [
    "Data is the third sort of function we deal with regularly - each instance of which we refer to as an *emprical function*.  The generic set of supervised learning data which we often denote by $\\left\\{\\mathbf{x}_p,y_p\\right\\}_{p=1}^P$ always defines a trivial rule for assigning input to output: pairing.  The input $\\mathbf{x}_p$ is simply paired with its output $y_p$.  This perahps can be more easily see by listing off each data pair in a table, as shown below. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "X4ckXt_G1EbD"
   },
   "source": [
    "\n",
    "\n",
    "<br>\n",
    "<table>\n",
    "    <thead style=\"background-color: #eee;\">\n",
    "        <tr>\n",
    "            <th>input: &nbsp;$\\mathbf{x}_p$</th>\n",
    "            <th>output: &nbsp;$y_p$</th>\n",
    "        </tr>\n",
    "    </thead>\n",
    "    <tbody>\n",
    "        <tr>\n",
    "            <td class=\"centered\">$\\mathbf{x}_1$</td>\n",
    "            <td class=\"centered\">$y_1$</td>\n",
    "        </tr>\n",
    "        <tr>\n",
    "            <td class=\"centered\">$\\mathbf{x}_2$</td>\n",
    "            <td class=\"centered\">$y_2$</td>\n",
    "        </tr>\n",
    "        <tr>\n",
    "            <td class=\"centered\">$\\vdots$</td>\n",
    "            <td class=\"centered\">$\\vdots$</td>\n",
    "        </tr>\n",
    "        <tr>\n",
    "            <td class=\"centered\">$\\mathbf{x}_P$</td>\n",
    "            <td class=\"centered\">$y_P$</td>\n",
    "        </tr>\n",
    "    </tbody>\n",
    "</table>\n",
    "<br>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0L08cKaB1EbE"
   },
   "source": [
    "These three categories of functions - *mathematical*, *algorithmic*, and *empircal* - are not mutually exclusive by any means.  For example, we can write down the formula of a line (a mathematical function) and implement it in code (an algorithmic function).  To visualize this line we can plug in a fine range of inputs into our implementation (an algorithmic function), producing a corresponding set of outputs, and plot the input/output pairs (an empircal dataset)."
   ]
  }
 ],
 "metadata": {
  "colab": {
   "include_colab_link": true,
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "68px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
